Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
disable elements when value = 1, enable them when value > 1

Using javascript only I am trying to say if cycn = 1, disable input element with id="prevdl"

if cycn > 1, then do not disable element with id="prevdl", and in both cases preview the value of cycn in the <p> with id="transit"

but condition after if (cycn = 1) is executed no matter what. And the one after else is not seen at all

HTML

<label for="cyclecount">Cycle Count:</label>
<input type="number" id="cyccnt" name="cyclecount" placeholder="Today's cycle number" min="1" max="6" autocomplete="off" value=""><br><br>

<p id="transit"></p>

<label for="previousdoseLevel">Previous Dose Level:</label>
<input type="number" id="prevdl" name="previousdoseLevel" placeholder="Insert Previous Dose Level" autocomplete="off" value=""><br><br>

Javascript

var cyc = document.getElementById("cyccnt");
var cycn = Number(cyc.value);
document.getElementById("cyccnt").oninput = function (e) { 
    if (cycn = 1) {
        document.getElementById("prevdl").disabled = true;
        document.getElementById("transit").innerHTML = cycn;   
    } else if (cycn >1) {
        document.getElementById("prevdl").disabled = false; 
        document.getElementById("transit").innerHTML = cycn;    
    }
    e.preventDefault(e);
}

please help and thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

use double ==

if (cycn == 1) {
  document.getElementById("prevdl").disabled = true;
  document.getElementById("transit").innerHTML = cycn;   
}

and take the value from the event instead.

document.getElementById("cyccnt").oninput = function (e) {
  e.preventDefault();
  var value = e.target.value
  document.getElementById("transit").innerHTML = value;    
  if (value && +value == 1) {
    document.getElementById("prevdl").disabled = true;
  } else {
    document.getElementById("prevdl").disabled = false; 
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda